#!/bin/bash

set -e          # exit on error
set -o pipefail # exit on pipeline error
set -u          # treat unset variable as error

SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"

. /minioslib || exit 1

if [ $DISTRIBUTION_TYPE = "debian" ]; then
    echo 'deb http://download.opensuse.org/repositories/home:/stevenpusser/Debian_10/ /' | tee /etc/apt/sources.list.d/home:stevenpusser.list
    curl -fsSL https://download.opensuse.org/repositories/home:stevenpusser/Debian_10/Release.key | gpg --dearmor >/etc/apt/trusted.gpg.d/home_stevenpusser.gpg
elif [ $DISTRIBUTION_TYPE = "ubuntu" ]; then
    echo 'deb http://download.opensuse.org/repositories/home:/stevenpusser/xUbuntu_20.04/ /' | tee /etc/apt/sources.list.d/home:stevenpusser.list
    curl -fsSL https://download.opensuse.org/repositories/home:stevenpusser/xUbuntu_20.04/Release.key | gpg --dearmor >/etc/apt/trusted.gpg.d/home_stevenpusser.gpg
fi

# install packages
pkg update
pkg install palemoon

if [[ $DESKTOP_ENVIRONMENT == *"xfce"* ]] && [ $PACKAGE_VARIANT != "puzzle" ]; then
    if [ ! -d /etc/skel/.config/xfce4 ]; then
        mkdir -p /etc/skel/.config/xfce4
    fi
    if [ $PACKAGE_VARIANT = "minimum" ]; then
        cat <<EOF >/etc/skel/.config/xfce4/helpers.rc
TerminalEmulator=xterm
FileManager=pcmanfm
WebBrowser=palemoon

EOF

    elif [ $PACKAGE_VARIANT = "standard" ] || [ $PACKAGE_VARIANT = "toolbox" ]; then
        cat <<EOF >/etc/skel/.config/xfce4/helpers.rc
TerminalEmulator=xfce4-terminal
FileManager=Thunar
WebBrowser=palemoon

EOF
    fi
fi

PACKAGE="palemoon"
echo "PACKAGE=$PACKAGE" >/.package
echo "VERSION=$(dpkg -s $PACKAGE | grep Version | sed 's/Version: //g' | sed 's/:/-/g')" >>/.package
